using NUnit.Framework;

// ReSharper disable InconsistentNaming
namespace NFreeMarker.Tests.Template
{
    public class TemplateTests_ProcessMissingValueOperations
    {
        [TestFixture]
        public class When_processing_a_default_value_operator : TemplateTestsBase
        {
            [Test]
            public void Assure_the_specified_default_value_is_returned_when_the_value_is_missing()
            {
                SetTemplateContent("${message!'No message'}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("No message"));
            }

            [Test]
            public void Assure_an_empty_string_is_returned_when_the_value_is_missing()
            {
                SetTemplateContent("${message!}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo(""));
            }

            [Test]
            public void Assure_the_value_is_returned_when_the_value_exists()
            {
                SetTemplateContent("${message!'No message'}");
                AddTemplateVariable("message", "Hello world");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("Hello world"));
            }
        }   

        [TestFixture]
        public class When_processing_a_missing_value_test_operator : TemplateTestsBase
        {
            [Test]
            public void Assure_false_is_returned_when_the_value_is_missing()
            {
                SetTemplateContent("${(message??)?string}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("false"));
            }

            [Test]
            public void Assure_true_is_returned_when_the_value_exists()
            {
                SetTemplateContent("${(message??)?string}");
                AddTemplateVariable("message", "Hello world");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("true"));
            }
        }   
    }
}
// ReSharper enable InconsistentNaming
